<?php
class admin extends Model {

/*    function __construct()
    {
        parent::__construct();
    }*/
    
    function insert(){
       $this->username = $_POST['username'];
	   $this->password = $_POST['password'];
	   $this->role = $_POST['role'];
	   $this->name = $_POST['name'];
	   $this->department = $_POST['department'];
	   $this->post = $_POST['post'];
	   $this->title = $_POST['title'];
	   $this->remarks = $_POST['remarks'];
       $this->createtime = time();
       $result = $this->db->insert('admin',$this);
       return $result;
    }
    
    function auth($name){
    	$this->db->where(array('username'=>trim($name)));
    	$this->db->from('admin');
        $result = $this->db->count_all_results(); 
        return $result;
    }

	function login($array){
		$this->db->where($array);
		$query = $this->db->get('admin');
		$result= $query->result();
		return $result;
	}
    
    function select($id,$num="",$offset=""){
       $this->db->limit($num,$offset);	
       if($id!=""){
       	  $this->db->where(array('admin_id'=>$id));
       }
       $query = $this->db->get('admin');
       $result = $query->result(); 
       return $result;
    }
    
    function update($id){
//       $this->username = $_POST['username']; 
	   $this->password = $_POST['password'];
	   $this->name = $_POST['name'];
	   $this->department = $_POST['department'];
	   $this->post = $_POST['post'];
	   $this->title = $_POST['title'];
	   $this->remarks = $_POST['remarks'];
       $this->role = $_POST['role'];
       $result = $this->db->update('admin',$this,array('admin_id'=>$id));
       return $result;
    }
    
    function update_reset($id){
    	$this->password = '000000';
    	$result = $this->db->update('admin',$this,array('admin_id'=>$id));
       return $result;
    }
    
    function del($id){
       $result = $this->db->delete('admin',array('admin_id'=>$id));
       return $result;
    }
}
?>